package com.yjhb.android.sbz

import com.yjhb.android.sbz.BuildConfig
import com.yjhb.android.sbz.entity.UserInfo
import com.yjhb.android.sbz.manager.OSSManager
import com.yjhb.android.sbz.tool.DataSaveTool
import com.yjhb.android.sbz.tool.UserTool
import com.yjhb.android.sbz.tool.wx.WxTool
import com.jojo.android.zxlib.base.BaseApplication
import com.jojo.android.zxlib.tool.ZxLogTool
import com.tencent.imsdk.v2.V2TIMSDKConfig
import com.tencent.qcloud.tim.uikit.TUIKit
import com.tencent.qcloud.tim.uikit.config.CustomFaceConfig
import com.tencent.qcloud.tim.uikit.config.GeneralConfig
import com.umeng.analytics.MobclickAgent

/**
 * 创建者 zx
 * 创建时间 2020/11/16 15:13
 */
class App : BaseApplication() {
    private val TAG = "App"
    override fun getBuglyId(): String {
        return if (BuildConfig.DEBUG) {
            "faf3e70cdd"
        } else {
            "bfd7ced8b5"
        }
    }

    override fun getDbName(): String {
        return "jiuBang_db"
    }

    override fun onCreate() {
        super.onCreate()
        WxTool.regToWx(this)
        //是否输出日志
        ZxLogTool.isDebug(BuildConfig.LOG_DEBUG)
        ZxLogTool.isUpload(true)
        userInfo = UserTool.fetchUserInfo()
        UUID = UserTool.UUID()

        // 配置 Config，请按需配置
        val configs = TUIKit.getConfigs()
        configs.sdkConfig = V2TIMSDKConfig()
        configs.customFaceConfig = CustomFaceConfig()
        configs.generalConfig = GeneralConfig()
        TUIKit.init(this, DataSaveTool.getIM_APP_ID(), configs)

        //快手
        initKSSDK();

        OSSManager.init(this)

    }

    override fun onTerminate() {
        ZxLogTool.e("APP被杀")
        MobclickAgent.onKillProcess(this)
        super.onTerminate()
    }

    fun initKSSDK() {


    }

    companion object {
        @JvmField
        var userInfo: UserInfo? = null


        @JvmField
        var UUID: String? = null

        @JvmStatic
        fun updateUserInfo(userInfo: UserInfo?) {
            Companion.userInfo = userInfo
            UserTool.saveUserInfo(userInfo)
        }


        @JvmStatic
        fun updateUUID(UUID: String?) {
            Companion.UUID = UUID
            UserTool.saveUUID(UUID)
        }
    }
}